package com.sikao.app.adapter;

/**
 * Created by Sun on 2017/1/12.
 */

import android.widget.ImageView;


        import java.util.ArrayList;
        import java.util.List;

        import android.content.Context;
        import android.view.LayoutInflater;
        import android.view.View;
        import android.view.ViewGroup;
        import android.widget.BaseAdapter;
        import android.widget.ImageView;

import com.nostra13.universalimageloader.core.ImageLoader;
import com.sikao.app.R;
import com.sikao.app.bean.BrandListBean;
import com.sikao.app.net.HttpApi;

public class BrandListItemAdapter extends BaseAdapter {

    private List<BrandListBean.ResBean> objects = new ArrayList<BrandListBean.ResBean>();

    private Context context;
    private LayoutInflater layoutInflater;

    public BrandListItemAdapter(Context context, List<BrandListBean.ResBean> beans) {
        this.context = context;
        this.objects = beans;
        this.layoutInflater = LayoutInflater.from(context);
    }

    @Override
    public int getCount() {
        return objects.size();
    }

    @Override
    public BrandListBean.ResBean getItem(int position) {
        return objects.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        if (convertView == null) {
            convertView = layoutInflater.inflate(R.layout.brand_list_item, null);
            convertView.setTag(new ViewHolder(convertView));
        }
        initializeViews((BrandListBean.ResBean)getItem(position), (ViewHolder) convertView.getTag());
        return convertView;
    }

    private void initializeViews(BrandListBean.ResBean object, ViewHolder holder) {
        //TODO implement
        ImageLoader.getInstance().displayImage(HttpApi.BANNERUTL+object.getBrand_image_path(),holder.ivBrand);
    }

    protected class ViewHolder {
        private ImageView ivBrand;

        public ViewHolder(View view) {
            ivBrand = (ImageView) view.findViewById(R.id.iv_brand);
        }
    }
}
